package com.example.blueconn.fragment.bl;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.blueconn.R;
import com.example.blueconn.data.FxData;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by zhudongao
 * Desc
 * Date 4/13/21
 */

public class BlViewParamAdapter extends RecyclerView.Adapter<BlViewParamAdapter.BlViewParamVH> {

    private List<FxData> listData = new ArrayList<>();

    @NonNull
    @Override
    public BlViewParamVH onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_view_param, null);
        return new BlViewParamVH(view);
    }

    @Override
    public void onBindViewHolder(@NonNull BlViewParamVH holder, int position) {
        holder.setData(listData.get(position));
    }

    @Override
    public int getItemCount() {
        return listData.size();
    }

    public List<FxData> getListData() {
        return listData;
    }

    public void setListData(List<FxData> listData) {
        this.listData = listData;
    }

    public static class BlViewParamVH extends RecyclerView.ViewHolder {

        private View f2Area;
        private TextView number;
        private TextView slopA;
        private TextView nodeA;
        private TextView slopB;
        private TextView nodeB;
        public BlViewParamVH(@NonNull View itemView) {
            super(itemView);
            number = itemView.findViewById(R.id.number);
            f2Area = itemView.findViewById(R.id.f2_area);
            slopA = itemView.findViewById(R.id.slop1);
            nodeA = itemView.findViewById(R.id.node1);
            slopB = itemView.findViewById(R.id.slop2);
            nodeB = itemView.findViewById(R.id.node2);
        }

        public void setData(FxData data) {
            slopA.setText(String.valueOf(data.slopA));
            nodeA.setText(String.valueOf(data.nodalA));
            if ("L".equals(data.dataType)) {
                number.setText("照度(通道" + data.number + ")");
                f2Area.setVisibility(View.VISIBLE);
                slopB.setText(String.valueOf(data.slopB));
                nodeB.setText(String.valueOf(data.nodalB));
            } else {
                number.setText("温度(通道" + data.number + ")");
                f2Area.setVisibility(View.GONE);
            }
        }
    }
}
